<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        const obj = {
            name: '洪',
            age: 20
        }
        localStorage.setItem('name', obj);
        console.log(localStorage.getItem('name'));
        //因为本地存储只能存储字符串
        //存储复杂数据类型 obj对象形式 必须转成JOSN字符串形式
        //JSON.stringify(键值);
        localStorage.setItem('name1', JSON.stringify(obj));
        console.log(JSON.parse(localStorage.getItem('name1')));
        //转对象 JSON.parse(localStorage.getItem('键名'));
        console.log(JSON.parse(localStorage.getItem('name1')));

    </script>
</body>

</html>